package com.example.myapplication.part03.part08;

import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;


public class part8_03Activity extends AppCompatActivity {

    private ImageView bulbImage;
    private Switch lightSwitch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_part803);

        // 初始化视图
        bulbImage = findViewById(R.id.bulb_image);
        lightSwitch = findViewById(R.id.light_switch);

        // 设置Switch状态改变监听器
        lightSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    // 开关打开 - 点亮灯泡
                    bulbImage.setImageResource(R.drawable.ic_light_on);
//                    bulbImage.setColorFilter(Color.YELLOW); // 添加黄色光晕效果
                    Toast.makeText(part8_03Activity.this, "灯泡已点亮", Toast.LENGTH_SHORT).show();
                } else {
                    // 开关关闭 - 熄灭灯泡1
                    bulbImage.setImageResource(R.drawable.ic_light_off);
                    bulbImage.clearColorFilter(); // 清除颜色滤镜
                    Toast.makeText(part8_03Activity.this, "灯泡已关闭", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}